package logic

import (
	"context"
	"errors"
	"strconv"
	"user-login1/models/mysql"

	"user-login1/userrpc/internal/svc"
	"user-login1/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserShowLogic {
	return &UserShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 查看个人信息
func (l *UserShowLogic) UserShow(in *userrpc.UserShowRequest) (*userrpc.UserShowResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	if err := user.FindUserShow(mysql.DB, strconv.FormatInt(in.UserId, 10)); err != nil {
		return nil, errors.New("用户不存在,查询失败")
	}

	return &userrpc.UserShowResponse{
		Mobile:     user.Mobile,
		Password:   user.Password,
		HeadImage:  user.HeadImage,
		NickName:   user.NickName,
		Address:    user.Address,
		WechatCode: user.WechatCode,
	}, nil
}
